 // eslint-disable-next-line
 /* eslint-disable */
import apiConfig from './api_router.js'
import axios from 'axios'
// 设置全局的baseURL配置
axios.defaults.baseURL = process.env.NODE_ENV==="development"?'/admin/':"http://118.190.209.124/account/admin/";

/**
 * api.login({
 *     username: 'qwe',
 *     password: 123456
 * }).then((res) => {
 *     console.log(res)
 * })
 */
const obj = {}

for (let i in apiConfig) {
    let config = apiConfig[i]
    obj[i] = function(params) {
        return new Promise((resolve, reject) => {
            let opt = {
                method: config.method || 'get',
                url: config.url
            }
            if (config.method == 'post') {
                opt.data = params
            } else {
                opt.params = params
            }
            axios(opt)
                .then(res => {
                    if (res.data.code == 0) {
                        resolve(res.data)
                    } else {
                        console.log(res.data.msg)
                        reject(res.data)
                    }
                })
                .catch(error => {
                    console.log(error)
                    // alert('网络遇到问题，请稍后再试')
                })
        })
    }
}
export default obj
/**
axios(config)
// 发送 POST 请求
axios({
  method: 'post',
  url: '/user/12345',
  data: {
    firstName: 'Fred',
    lastName: 'Flintstone'
  }
});
axios(url[, config])
// 发送 GET 请求（默认的方法）
axios('/user/12345');
 */
